<?php
// +----------------------------------------------------------------------
// | PHP [ JUST YOU ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2017 http://www.jyphp.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: FlyingPig <flyingpigfp@163.com>
// +----------------------------------------------------------------------

namespace App\Model\Vip;


use App\Model\Base;
use Illuminate\Support\Facades\DB;

class VipConfList extends Base
{

    protected $table = 't_vip_conf';


    protected $appends = ['open_desc', 'login_desc'];


    public function getOpenDescAttribute()
    {
        return $this->type(
            DB::table('t_item_activity_conf')->where('type', $this->activity_conf_type_open)->value('rule')
        );
    }

    public function getLoginDescAttribute()
    {
        return $this->type(
            DB::table('t_item_activity_conf')->where('type', $this->activity_conf_type_login)->value('rule')
        );
    }

    private function type($rule)
    {
        if (empty($rule)) {
            return '';
        }
        $data = [];
        $rule = explode('|', $rule);
        foreach ($rule as $value) {
            $value_arr = explode(':', $value);
            $object = DB::table('t_item_conf')->where('id', $value_arr[0])->first(['type','reward']);
            switch ($object->type) {
                case 5:
                    $data['room_ticket'] = $object->reward;
                    break;
                case 3:
                    $data['diamonds'] = $object->reward;
                    break;
                case 6:
                    $data['quickly_grab'] = $object->reward;
                    break;

            }
        }
        return $data;
    }

}